package com.sc.study.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.study.dao.StudyPlanMapper;
import com.sc.study.dto.PlanQueryDTO;
import com.sc.study.entity.StudyPlan;
import com.sc.study.service.StudyPlanService;
import com.sc.study.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 学习计划服务impl
 *
 * @author 徐赫阳
 * @date 2021/09/27
 */
@Service
@Component
public class StudyPlanServiceImpl extends ServiceImpl<StudyPlanMapper, StudyPlan> implements StudyPlanService {

    /**
     * 学习计划刀
     */
    @Autowired
    private StudyPlanMapper studyPlanMapper;

    @Override
    public PageVO<StudyPlan> getPlanList(PlanQueryDTO queryDTO){

        QueryWrapper<StudyPlan> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .like(queryDTO.getContent() != null,StudyPlan::getTitle,queryDTO.getContent())
                .like(queryDTO.getContent() != null,StudyPlan::getContent,queryDTO.getContent())
                .eq(queryDTO.getStatus() != null,StudyPlan::getStatus,queryDTO.getStatus())
                .orderByDesc(StudyPlan::getId);
        Integer count = this.studyPlanMapper.selectList(queryWrapper).size();
        List<StudyPlan> list = this.studyPlanMapper.selectList(queryWrapper.lambda().last("LIMIT "+ (queryDTO.getPage() - 1) * queryDTO.getPageSize() + ","+ queryDTO.getPageSize()));
        return PageVO.setPage(queryDTO.getPage(),queryDTO.getPageSize(),list,count);
    }


}
